#include "gameselect.h"
#include "ui_gameselect.h"

GameSelect::GameSelect(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::GameSelect)
{
    ui->setupUi(this);
    this->setWindowIcon(QIcon(":/res/ico.png"));
    this->setWindowTitle("GreedySnake game");
}

GameSelect::~GameSelect()
{
    delete ui;
}

void GameSelect::paintEvent(QPaintEvent *event)
{
    (void)event;
    QPainter painter(this);
    QPixmap pix(":/res/select.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

void GameSelect::on_back_clicked()
{
    this->close();
    GameHall *gamehall=new GameHall;
    gamehall->show();
}

void GameSelect::on_simple_clicked()
{
    this->close();
    GameRoom *gameroom=new GameRoom;
    gameroom->setWindowTitle("simple mode");
    gameroom->SetMode(SIMPLE);
    gameroom->show();

}

void GameSelect::on_normal_clicked()
{
    this->close();
    GameRoom *gameroom=new GameRoom;
    gameroom->setWindowTitle("normal mode");
    gameroom->SetMode(NORMAL);
    gameroom->show();
}

void GameSelect::on_hard_clicked()
{
    this->close();
    GameRoom *gameroom=new GameRoom;
    gameroom->setWindowTitle("hard mode");
     gameroom->SetMode(HARD);
    gameroom->show();
}



void GameSelect::on_historical_clicked()
{
    QFile file("D:/GreedySnake/Snake/his_score.txt");
    int ret=file.open(QIODevice::ReadOnly);
    if(ret==false)
        exit(-1);
    QTextStream in(&file);
    GameScore *gameScore=new GameScore;
    while(!in.atEnd())
    {
       QString score=file.readLine();
       gameScore->setItem(score);
    }

    file.close();
    gameScore->show();

}
